/* jshint esversion: 8 */
import * as types from '@/store/types.js';
import { getStoreInfo,getHomePageData } from '@/api/app.js';

export default {
  state: {
    StoreInfo: {
      "StoreName": "鹿城区站前花牧春花店",
      "CreditCode": "92330302MA2C5HU30R",
      "ContactPerson": "陈女士",
      "Phone": "18433030261",
      "CompanyType": "个体工商户",
      "OperatingPeriod": "-",
      "StoreStatus": "正常营业",
      "DoorHead": "",
      "Address": "温州市鹿城区站前东小区双龙大楼A幢120号"
    },
    HomePageData: {},
  },
  
  getters: {
    /*** 返回 店铺信息 数据 ***/
    [types.GStoreInfo](state) {
      return state.StoreInfo;
    },
    /**
    * 返回 首屏列表 数据
    */
    [types.GHomePageData](state) {
        return state.HomePageData;
    },
  },

  actions: {
    /*** 获取 店铺信息 数据 ***/
    [types.AStoreInfo](ctx) {
      return new Promise((resolve, reject) => {
        getStoreInfo().then((data) => {
          ctx.commit(types.MStoreInfo, data);
          resolve();
        }).catch(error => {
          ctx.commit(types.MStoreInfo, {});
          reject(error);
        });
      });
    },
    /**
     * 获取 首屏列表 数据
     */
    [types.AHomePageData](ctx, query) {
      return new Promise((resolve, reject) => {
        getHomePageData(query).then(({data}) => {
           ctx.commit(types.MHomePageData,data);
           resolve();
        }).catch(error => {
           ctx.commit(types.MHomePageData, {});
           reject(error);
        });
      });
    },
  },

  mutations: {
    /*** 填充 店铺信息 数据 ***/
    [types.MStoreInfo](state, access) {
      state.StoreInfo = access;
    },
    /**
    * 填充 首屏幕列表 数据
    */
    [types.MHomePageData](state, access) {
        state.HomePageData = access;
    },
  }
};